<template>
  <div class="app-draw-add">
	  <u-navbar :is-back="false" title="退货单填写"
	    title-size="30"
	    :background="{background:'#2B88FE' }"
	    title-color="#fff">
	    <div class="head_icon">
	      <u-icon @click="$api.handleBackTo"
	        name="arrow-left" color="#fff"
	        size="36">
	      </u-icon>
	      <u-icon @click="$api.handleHomeTo"
	        name="home" color="#fff" size="36">
	      </u-icon>
	    </div>
	  </u-navbar>
	  
 
    <navigator url="/pages/sale/draw/drawSelect" class="draw-add">
      <u-icon name="plus" color="#2979ff" size="28"></u-icon> 添加退货商品
    </navigator>
    <appProduct v-for="(v,i) in formdata" :key="i" :li="v">
      <view slot="cell" style="display:flex">
        <span> 退货数量：</span>
        <u-input border type="text" v-model="v.fCarCount"></u-input>
      </view>
    </appProduct>
	<view class="h16">
	
	</view>
	
	<div class="draw-mark">
	  <span>退款金额：</span>
	  <input placeholder="请输入" v-model="form.PayMoney " type="digit"
	     class="x-col x-col-center"></input> 元
 
	</div>
	<view class="h16">
	
	</view>
    <div class="draw-mark">
      <span>退款说明：</span>
     <u-input type="textarea" v-model="form.PayInfo" border></u-input>
    </div>
    <div class="footer">
      <u-button>取消</u-button>
      <u-button type="primary" @click="handleSave">提交</u-button>
    </div>
  </div>
</template>

<script>
import appProduct from '@/components/app-product'
export default {
  components: {
    appProduct
  },
  data() {
    return {
		form: {
		  MrkId: this.id,
		  OrderId: this.willid,
		  WillId: this.willid,
		  PayInfo: '',
		  PayPic: '',
		  PayMoney: 0,
		  PayOrBack:2,
		  NoPay: 0,
		  PayType: 4,
		  OrderOrWill:2
		},
  
	  detail: {},
	  willid: 0,
	  id: 0,
	  clineOnce:true,
      formdata: [],
      list: '',
	  header: {
	    token: uni.getStorageSync('token')
	  }
    }
  },
  onLoad(e) {
    uni.setNavigationBarTitle({
      title: '新增退款记录'
    })
  	 this.id = Number(e.id)
  	 this.willid = Number(e.willid)
  	 this.$axios('api/MrkNoPayWill/GetDetail', 'post', { value: e.willid }).then(res => {
  	    this.detail = res.Value
  	 })
  },
  methods: {
    handleSave() {
		if (!this.clineOnce) return false
		this.clineOnce = false
		this.form.MrkId=this.id
		 this.form.OrderId=this.detail.fOrderId
		  this.form.OrderOrWill=this.detail.fWillType
		  this.form.WillId=this.willid
		  
      this.$axios('api/PayInfo/AddPayBackSave', 'post', { value: this.form }).then(ret => {
		  
		  let list = this.formdata.map(x => ({ 
			  fOrderPayId: ret.Value, 
			  fMrkId: this.form.MrkId, 
			  fWillId: this.form.WillId, 
			  fProId: x.fId, 
			  fProName: x.fTitle, 			 
			  fCount: x.fCarCount  }))
		    
        this.$axios('api/OrderPayBackPro/AddListDetail', 'post', { value: list }).then(res => {
			if (!res.Success) {
			  uni.showToast({
			    title: '提交失败：'+res.Message,
			    icon: 'none',
			    duration: 2000
			  })
			 this.clineOnce = true
			  return false
			}
          this.clineOnce = true
        this.$api.handleToUrl('提交成功', '/pages/my_customer/PayWillDetail?id='+this.id +'&willid='+this.willid)
		   getApp().globalData.addCusGoodLi=null
        })
      })
    }
  },
  onShow() {
    if (getApp().globalData.addCusGoodLi) {
      let orders = getApp().globalData.addCusGoodLi
      orders.forEach(
        x =>
          (x.details = [
            { label: '价格（元）', value: x.fSallPrice }
          ])
      )
      this.formdata = orders
    }
  } 
}
</script>

<style lang="scss" scoped>
.app-draw-add {
  padding-bottom: 70rpx;
  .draw-item {
    .title {
      font-size: 30rpx;
      color: #7f7f7f;
      margin-top: 30rpx;
      margin-left: 30rpx;
    }
  }
  .draw-add {
    color: #007aff;
    font-size: 30rpx;
    padding: 32rpx;
    text-align: center;
  }
  .draw-mark {
    display: flex;
    padding: 0 32rpx;
    u-input {
      flex: 1;
    }
  }
  .footer {
    margin-top: 32rpx;
    display: flex;
    justify-content: center;
    position: sticky;
    bottom: 2%;
    u-button,
    .u-btn {
      width: 40%;
    }
    u-button + u-button {
      margin-left: 30rpx;
    }
  }
  .h16 {
    height: 16rpx;
    background-color: #f5f7f9;
  }
  
  .txtinput {
    height: 30rpx;
    background: #f8f9fc;
    border-radius: 16rpx;
    border: 2rpx solid rgba(0, 0, 0, 0.09);
    padding: 22rpx 20rpx;
    box-sizing: border-box;
    width: 60%;
  }
}

</style>